//
//  View3Controller.m
//  方块布局
//
//  Created by KL on 16/12/1.
//  Copyright © 2016年 KM. All rights reserved.
//

#import "View3Controller.h"

@interface MyCell : UICollectionViewCell<UIScrollViewDelegate>
{
    UIScrollView *sco;
}
@property (strong,nonatomic)UIImageView *iv;

@end

@implementation MyCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    sco = [[UIScrollView alloc]initWithFrame:self.bounds];
    sco.minimumZoomScale = 1;
    sco.maximumZoomScale = 3;
    sco.delegate = self;
    [self.contentView addSubview:sco];
    _iv = [[UIImageView alloc]initWithFrame:sco.bounds];
    _iv.contentMode = UIViewContentModeScaleAspectFit;
    [sco addSubview:_iv];
    
    return self;
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    NSLog(@"ncklxdcnkl");
    return _iv;
}

@end


@interface View3Controller ()<UICollectionViewDelegate,UICollectionViewDataSource>
{
    UICollectionViewFlowLayout *flow;
    UICollectionView *coll;
}
@end

@implementation View3Controller

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    flow = [[UICollectionViewFlowLayout alloc]init];
    flow.minimumLineSpacing = 1;
    flow.minimumInteritemSpacing = 1;
    flow.itemSize = self.view.frame.size;
    flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    coll = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flow];
    coll.delegate = self;
    coll.dataSource = self;
    coll.pagingEnabled = YES;
    [self.view addSubview:coll];
    [coll registerClass:[MyCell class] forCellWithReuseIdentifier:@"ce"];
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _im.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ce" forIndexPath:indexPath];
    cell.iv.image = _im[indexPath.item];
    
    return cell;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
